package org.cfg;

import com.sojoys.artifact.build.data.base.BaseCfg;
import java.util.List;
import com.sojoys.artifact.tools.ToolMap;
import com.sojoys.artifact.tools.ToolCopy;
import com.sojoys.artifact.factory.bytebuff.IByteBuff;
import java.util.Map;
import com.alibaba.fastjson.JSONObject;
import com.sojoys.artifact.constant.DataModelKeyEnum;
/**
 * 约会规则
 */
public class DatingRuleCfg extends BaseCfg<DatingRuleCfg> {

	/**
	 * 数据库表名称
	 */
	public static final String TABLE_NAME = "dating_rule";
	/**
	 * 完整类名称
	 */
	public static final String CLASS_NAME = "org.cfg.DatingRuleCfg"; 
	/**
	 * 字段个数
	 */
	public static final int COLUMN_COUNT= 7;
	/**
	 * 数据库源字段注释
	 */
	public static final String[] SOURCE_COLUMN_REMARKS = new String[]{"","剧本类型","进入条件","失败条件","其他信息","初始节点id","其它剧本列表(约会可能会有多个剧本号，如预定约会)",};
	/**
	 * 数据库源字段名字
	 */
	public static final String[] SOURCE_COLUMN_NAMES = new String[]{"id","type","enter_condition","fail_condition","other_info","start_node_id","other_script_ids",};
	/**
	 * 拼音字段名字
	 */
	public static final String[] PINGYING_COLUMN_NAMES = new String[]{"id","type","enterCondition","failCondition","otherInfo","startNodeId","otherScriptIds",};
	/**
	 * HashCode字段名字
	 */
	public static final Integer[] HASHCODE_COLUMN_NAMES = new Integer[]{3355,3575610,1595195508,-901353158,-182548355,240178587,-582482477,};
	/**
	 * 字段基本类型
	 */
	public static final String[] COLUMN_BASICTYPES = new String[]{"int","int","Map","Map","Map","int","List",};
	/**
	 * 字段引用类型
	 */
	public static final Class[] COLUMN_CLASSTYPES = new Class[]{Integer.class,Integer.class,Map.class,Map.class,Map.class,Integer.class,List.class,};
	
	/**
	 * id
	 */
	private int id;
	
	/**
	 * 剧本类型
	 */
	private int type;
	
	/**
	 * 进入条件
	 */
	private Map enterCondition;
	
	/**
	 * 失败条件
	 */
	private Map failCondition;
	
	/**
	 * 其他信息
	 */
	private Map otherInfo;
	
	/**
	 * 初始节点id
	 */
	private int startNodeId;
	
	/**
	 * 其它剧本列表(约会可能会有多个剧本号，如预定约会)
	 */
	private List otherScriptIds;
	
	
	
	public static DatingRuleCfg builder() {
		DatingRuleCfg datingRuleCfg = new DatingRuleCfg();
		return datingRuleCfg;
	}
	
	/**
	 * id
	 */
	public int getId() {
		return id;
	}
	
	/**
	 * 剧本类型
	 */
	public int getType() {
		return type;
	}
	
	/**
	 * 进入条件
	 */
	public Map getEnterCondition() {
		return enterCondition;
	}
	
	/**
	 * 失败条件
	 */
	public Map getFailCondition() {
		return failCondition;
	}
	
	/**
	 * 其他信息
	 */
	public Map getOtherInfo() {
		return otherInfo;
	}
	
	/**
	 * 初始节点id
	 */
	public int getStartNodeId() {
		return startNodeId;
	}
	
	/**
	 * 其它剧本列表(约会可能会有多个剧本号，如预定约会)
	 */
	public List getOtherScriptIds() {
		return otherScriptIds;
	}
	
	
	protected Object[] getColumnNames(DataModelKeyEnum e){
		switch (e) {
		case SOURCE:
			return SOURCE_COLUMN_NAMES;
		case PINGYING:
			return PINGYING_COLUMN_NAMES;
		case HASHCODE:
			return HASHCODE_COLUMN_NAMES;
		case REMARKS:
			return SOURCE_COLUMN_REMARKS;
		default:
			return PINGYING_COLUMN_NAMES;
		}
	}
	
	protected String[] getBasicTypes(){
		return COLUMN_BASICTYPES;
	}
	
	protected Class[] getClassTypes(){
		return COLUMN_CLASSTYPES;
	}
	
	protected Object[] getColumeValues(){
		Object[] values = new Object[COLUMN_COUNT];
        values[0] = this.id;
        values[1] = this.type;
        values[2] = this.enterCondition;
        values[3] = this.failCondition;
        values[4] = this.otherInfo;
        values[5] = this.startNodeId;
        values[6] = this.otherScriptIds;
        return values;
	}
	
	protected DatingRuleCfg createColumeValues(Object[] vals) {
		this.id = (int)vals[0];
		this.type = (int)vals[1];
		this.enterCondition = (Map)vals[2];
		this.failCondition = (Map)vals[3];
		this.otherInfo = (Map)vals[4];
		this.startNodeId = (int)vals[5];
		this.otherScriptIds = (List)vals[6];
		return this;
	}
	
	protected Map<Object, Object> toMap(Object[] keys,Map<Object, Object> map){
        map.put(keys[0], this.id);
        map.put(keys[1], this.type);
        map.put(keys[2], this.enterCondition);
        map.put(keys[3], this.failCondition);
        map.put(keys[4], this.otherInfo);
        map.put(keys[5], this.startNodeId);
        map.put(keys[6], this.otherScriptIds);
        return map;
    }
    
    protected DatingRuleCfg createForMap(Object[] keys,Map map){
   		this.id = (int)map.get(keys[0]);
   		this.type = (int)map.get(keys[1]);
   		this.enterCondition = (Map)map.get(keys[2]);
   		this.failCondition = (Map)map.get(keys[3]);
   		this.otherInfo = (Map)map.get(keys[4]);
   		this.startNodeId = (int)map.get(keys[5]);
   		this.otherScriptIds = (List)map.get(keys[6]);
        return this;
    }
	
	
	protected JSONObject toJSONObject(Object[] keys,JSONObject obj){
        obj.put(keys[0], this.id);
        obj.put(keys[1], this.type);
        obj.put(keys[2], this.enterCondition);
        obj.put(keys[3], this.failCondition);
        obj.put(keys[4], this.otherInfo);
        obj.put(keys[5], this.startNodeId);
        obj.put(keys[6], this.otherScriptIds);
        return obj;
    }
    
    protected DatingRuleCfg createForJSONObject(Object[] keys,JSONObject obj){
	    this.id = obj.getIntValue(keys[0]);
	    this.type = obj.getIntValue(keys[1]);
		this.enterCondition = obj.getObject(keys[2],Map.class);
		this.failCondition = obj.getObject(keys[3],Map.class);
		this.otherInfo = obj.getObject(keys[4],Map.class);
	    this.startNodeId = obj.getIntValue(keys[5]);
		this.otherScriptIds = obj.getObject(keys[6],List.class);
        return this;
    }
    
    protected void writeBytes(IByteBuff byteBuf){
	    byteBuf.writeInt(this.id);
	    byteBuf.writeInt(this.type);
	    byteBuf.writeObject(this.enterCondition);
	    byteBuf.writeObject(this.failCondition);
	    byteBuf.writeObject(this.otherInfo);
	    byteBuf.writeInt(this.startNodeId);
	    byteBuf.writeObject(this.otherScriptIds);
    }
	
	protected DatingRuleCfg readBytes(IByteBuff byteBuf){
	    this.id = byteBuf.readInt(null);
	    this.type = byteBuf.readInt(null);
	    this.enterCondition = (Map)byteBuf.readObject();
	    this.failCondition = (Map)byteBuf.readObject();
	    this.otherInfo = (Map)byteBuf.readObject();
	    this.startNodeId = byteBuf.readInt(null);
	    this.otherScriptIds = (List)byteBuf.readObject();
	    return this;
	}
	
	public DatingRuleCfg deepCopy(){
		DatingRuleCfg datingRuleCfg = null;
		try {
			datingRuleCfg = (DatingRuleCfg) super.clone();
		    datingRuleCfg.enterCondition = ToolCopy.copyObject(this.enterCondition);
		    datingRuleCfg.failCondition = ToolCopy.copyObject(this.failCondition);
		    datingRuleCfg.otherInfo = ToolCopy.copyObject(this.otherInfo);
		    datingRuleCfg.otherScriptIds = ToolCopy.copyObject(this.otherScriptIds);
			return datingRuleCfg;
		} catch (CloneNotSupportedException e) {
			e.printStackTrace();
		}
		return datingRuleCfg;
	}
//自定义内容起始位置

	public int getEnterCondtionByType(String type){
		if (enterCondition.get(type) != null){
			return (int) enterCondition.get(type);
		}
		return 0;
	}
//自定义内容结束位置
}
